from fastapi import FastAPI
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate
from langserve import add_routes
from models import get_ds_model_client

prompt = ChatPromptTemplate.from_messages([SystemMessagePromptTemplate.from_template("请将一下内容翻译成{language}"),
                                             HumanMessagePromptTemplate.from_template("{text}")])
client = get_ds_model_client()
parse = StrOutputParser()

chain = prompt | client | parse

app = FastAPI(title="基于LangChain的翻译服务", description="基于LangChain的翻译服务", version="0.0.1")
add_routes(app, chain, path="/tslServer")


if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)
